package com.hanter.android.safdemo

import android.Manifest
import android.app.Application
import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.annotation.RequiresPermission
import androidx.lifecycle.AndroidViewModel
import com.hanter.android.saf.SafManager
import com.hanter.android.saf.SafManagerImpl

/**
 * 文件名：MainViewModel <br/>
 * 描述：MainViewModel
 * 创建时间：2022/03/23 09:44
 *
 * @author wangmingshuo
 */
class MainViewModel(application: Application) : AndroidViewModel(application) {

    private val safManager: SafManager = SafManagerImpl(application)

    fun register(activity: ComponentActivity) {
        safManager.register(activity)
    }

    fun createImageUri(name: String): Uri? {
        return safManager.createImageUri(name)
    }

    @RequiresPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
    fun getMediaUri(type: String, fileName: String): Uri? {
        return safManager.getMediaUri(type, fileName)
    }

    @RequiresPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
    fun exists(type: String, fileName: String): Boolean {
        return safManager.exists(type, fileName)
    }

    fun delete(uri: Uri): Boolean {
        return safManager.delete(uri)
    }

    fun delete(uri: Uri, rowId: Long) {
        safManager.delete(uri, rowId)
    }

    fun delete(uri: Uri, callback: SafManagerImpl.OnDeleteCallback) {
        safManager.delete(uri, callback)
    }

    fun createMediaUri(type: String, fileName: String): Uri? {
        return safManager.createMediaUri(type, fileName)
    }


}